<?php

use yii\db\Migration;

class m180319_021008_check_count extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%check_count}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'mechanic_id' => $this->integer()->defaultValue(0)->comment('机构id'),
                'goods_id' => $this->integer()->defaultValue(0)->comment('商品id'),
                'orders_item_id' => $this->integer()->defaultValue(0)->comment('商品价格id'),
                'orders_items_relation_id' => $this->integer()->defaultValue(0)->comment('订单商品价格id'),
                'teacher_id' => $this->integer()->defaultValue(0)->comment('老师id'),
                'customer_id' => $this->integer()->defaultValue(0)->comment('会员id'),
                'student_id' => $this->integer()->defaultValue(0)->comment('学生id'),
                'class_id' => $this->integer()->defaultValue(0)->comment('班级id'),
                'class_lesson_id' => $this->integer()->defaultValue(0)->comment('班级id'),
                'check_id' => $this->integer()->defaultValue(0)->comment('打卡id'),
                'lesson' => $this->smallInteger()->defaultValue(0)->comment('课次'),
                'class_time' => $this->integer()->defaultValue(0)->comment('上课时间'),
                'price' => $this->decimal(10,2)->defaultValue(0)->comment('课次价格'),
                'settlement_price' => $this->decimal(10,2)->defaultValue(0)->comment('结算价格'),
                'status' => $this->smallInteger()->defaultValue(0)->comment('状态（0未结算1已结算）'),
                'check_type' => $this->smallInteger()->defaultValue(0)->comment('打卡状态（0学生打卡1代打卡）'),
                'check_user' => $this->integer()->defaultValue(0)->comment('打卡人id 学生/代打卡'),
                'class_type' => $this->string(20)->defaultValue(null)->comment('课次类型（奖学金appointment 消费consume）'),
                'created_at' => $this->integer()->defaultValue(0)->comment('添加时间'),
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropTable('{{%check_count}}');
        }
    }
}
